#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int mins = INT_MAX, maxs = -1;
    for (int i = 0; i < 6; ++i) {
        int t; cin >> t;
        mins = min(mins, t);
        maxs = max(maxs, t);
    }
    int n; cin >> n;
    int minn = INT_MAX, maxx = -1;
    for (int i = 0; i < n; ++i) {
        int t; cin >> t;
        minn = min(minn, t);
        maxx = max(maxx, t);
    }
    cout << abs((maxx-maxs) - (minn-mins));
    return 0;
}